package com.edee.bigday.order.controller;

import com.edee.bigday.order.entity.OrderEntity;
import com.edee.bigday.order.entity.OrderReturnReasonEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@Slf4j
@RestController
public class RabbitController {
    @Autowired
    RabbitTemplate rabbitTemplate;

    @GetMapping("/sendMsg")
    public String sendMessage(@RequestParam(value = "num",defaultValue = "10") Integer num){
        for (int i = 0; i < num; i++) {
            if (i % 2 == 0) {
                OrderReturnReasonEntity entity = new OrderReturnReasonEntity();
                entity.setId(10L);
                entity.setName("Test-" + i);
                entity.setStatus(2);
                String msg = "test123000";
                rabbitTemplate.convertAndSend("edee-java-exchange", "edee.java", entity,new CorrelationData(UUID.randomUUID().toString()));
                log.info("消息{}发送完成！", entity);
            } else {
                OrderEntity entity = new OrderEntity();
                entity.setId(201L);
                entity.setMemberId((long) i);
                entity.setBillHeader("Test-billHeader" + i);
                entity.setStatus(98);
                entity.setOrderSn(UUID.randomUUID().toString());
                String msg = "OrderTest0001112";
                rabbitTemplate.convertAndSend("edee-java-exchange", "edee000.java", entity,new CorrelationData(UUID.randomUUID().toString()));
                log.info("消息{}发送完成！", entity);
            }
        }
        return "ok，消息发送完毕！";
    }
}
